#include <mutex>
using namespace std;

class big
{
    friend void swapbig(big &a,big &b);
    private:
        mutex mutexbig;
        int a;
    public:
        big(int na):a(na){}
};

void swapbig(big &a,big &b)
{
    if(&a==&b)
    {
        return;
    }
    std::lock(a.mutexbig,b.mutexbig);
    std::lock_guard<std::mutex> la(a.mutexbig,std::adopt_lock);
    std::lock_guard<std::mutex> lb(b.mutexbig,std::adopt_lock);
    swap(a.a,b.a);
}

int main()
{
    big a(1);
    big b(2);
    swapbig(a,b);
}
